package com.vzoom.logdesensitization.logback;

import ch.qos.logback.classic.pattern.ClassicConverter;
import ch.qos.logback.classic.spi.ILoggingEvent;
import com.vzoom.logdesensitization.AtStringTemplate;
import com.vzoom.logdesensitization.config.DesensitizationStrategyHolder;

public class LogbackDesensitizationMessageConvert extends ClassicConverter {
    @Override
    public String convert(ILoggingEvent event) {
        if (!DesensitizationStrategyHolder.getEnable()) {
            return event.getFormattedMessage();
        }
        Object[] argumentArray = event.getArgumentArray();
        String message = event.getMessage();
        if (message.contains("{}")) {
            return AtStringTemplate.render(message, argumentArray);
        } else {
            return event.getMessage();
        }
    }
}
